package shuai7boy.vip.transform.mr.nu;

import java.io.IOException;
import java.sql.Date;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.IntWritable;

import shuai7boy.vip.common.GlobalConstants;
import shuai7boy.vip.transform.mr.IOutPutCollector;
import shuai7boy.vip.transformer.model.dim.StatsUserDimension;
import shuai7boy.vip.transformer.model.dim.base.BaseDimension;
import shuai7boy.vip.transformer.model.value.BaseStatsValueWritable;
import shuai7boy.vip.transformer.model.value.reduce.MapWritableValue;
import shuai7boy.vip.transformer.server.IDimensionConverter;

public class NewUserCollector implements IOutPutCollector {

	@Override
	public void collector(Configuration conf, BaseDimension key, BaseStatsValueWritable value, PreparedStatement pstmt,
			IDimensionConverter converter) throws IOException, SQLException {
		// TODO Auto-generated method stub

		StatsUserDimension statsUserDimension = (StatsUserDimension) key;
		MapWritableValue mapWritableValue = (MapWritableValue) value;
		IntWritable newInstallUsers = (IntWritable) mapWritableValue.getValue().get(new IntWritable(-1));

		int i = 0;
		pstmt.setInt(++i, converter.getDimensionIdByValue(statsUserDimension.getStatsCommon().getPlatform()));
		pstmt.setInt(++i, converter.getDimensionIdByValue(statsUserDimension.getStatsCommon().getDate()));
		pstmt.setInt(++i, newInstallUsers.get());
		pstmt.setString(++i, conf.get(GlobalConstants.RUNNING_DATE_PARAMES));
		pstmt.setInt(++i, newInstallUsers.get());
		pstmt.addBatch();
	}

}
